from page.page_index import PageIndex
from page.page_login import PageLogin


class LoginService:

    def __init__(self, driver, base_url):
        self.driver = driver
        self.base_url = base_url
        self.page_index = PageIndex(self.driver, self.base_url)  # 网页主页
        self.page_login = PageLogin(self.driver, self.base_url)  # 网页主页

    def test_login_001(self, data):
        self.page_index.open_index()  # 打开网页
        self.page_index.click_login()  # 点击登录
        # self.page_login.input_zhanghao()
        self.page_login.input_zhanghao(data["zanhao"])
        self.page_login.input_pwd(data["pwd"])
        self.page_login.click_login()
        res = self.page_login.assert_true()
        return res == data["yuqi"]

    def test_login_002(self, data):
        self.page_index.open_index()  # 打开网页
        self.page_index.click_login()  # 点击登录
        # self.page_login.input_zhanghao()
        self.page_login.input_zhanghao(data["zanhao"])
        self.page_login.input_pwd(data["pwd"])
        self.page_login.click_login()
        res = self.page_login.assert_error()
        return data["yuqi"] in res
